#Developed By Dylan Pavelko

import copy

class Property:
	'Base Property Object'
	def __init__(self, name):
		self.name=name


class NumberProperty(Property):
	'A number property'
	def __init__(self, name, minValue, maxValue, defaultOffValue):
		self.Property = Property(name)
		self.name=name
		self.minValue = minValue
		self.maxValue = maxValue
		self.defaultOffValue = defaultOffValue
		self.currentValue = defaultOffValue
		
	def setValue(self, value):
		self.currentValue = value
		
	def getValue(self):
		return self.currentValue


class Settings:
	'Settings for a Fixture Type'
	
	
	def __init__(self, name):
		self.properties = []
		self.name = name
		
	def addProperty(self, property):
		self.properties.append(property)

	def getProperty(self, name):
		i=0
		while self.properties[i].name is not name:
			i=i+1
		return self.properties[i]
		
	def getPropertyIndex(self, index):
		return self.properties[index]
		
		
class FixtureType:
	'Common base class for all Fixtures'
	fixTypeCount = 0
	
	def __init__(self, name, deviceType, numberOfChannels, deviceSettings):
		FixtureType.fixTypeCount += 1
		self.id = "FT" + str(FixtureType.fixTypeCount)
		self.name = name
		self.deviceType = deviceType
		self.channels = numberOfChannels
		self.deviceSettings = copy.deepcopy(deviceSettings)
		
	def toString(self):
		print "DMX FIXTURE TYPE- ID: "+ self.id, ", NAME: " + self.name, ", DEVICE TYPE: " \
			+self.deviceType, ", NUMBER OF CHANNELS: " + str(self.channels)
			
			
class Fixture:
	'Specific instances of Fixtures'
	fixCount = 0
	
	def __init__(self, name, fixtureType):
		Fixture.fixCount += 1
		self.id = "F" + str(Fixture.fixCount)
		self.name = name
		self.fixtureType = fixtureType	
		
	def toString(self):
		print "FIXTURE- ID: "+self.id, " , NAME:",self.name, ",TYPE:",self.fixtureType.name
		
		
class DMXFixture(Fixture):

	def __init__(self, name, fixtureType, dmxStartAddress):
		self.fixture = Fixture(name, fixtureType)
		self.name = name
		self.id = self.fixture.id
		self.DMXStartAddress = dmxStartAddress
		self.settings = fixtureType.deviceSettings
		
	def toString(self):
		print "FIXTURE- ID: "+self.id, " , NAME:",self.name, ", TYPE:", \
			self.fixture.fixtureType.name, self.fixture.fixtureType.deviceType, \
			", DMX START ADDRESS:", self.DMXStartAddress,", NUMBER OF CHANNELS:",self.fixture.fixtureType.channels	
	
	def setColorLabel(self, color):
		self.color = color
		
	def getColorLabel(self):
		return self.color
		
	def getProperty(self, propertyName):
		return self.settings.getProperty(propertyName)
	
class FixtureLibrary:

	def __init__(self):
		self.library = []
		
	def addFixtureToLibrary(self, fixture):
		self.library.append(fixture)
		
class ShowGrid:
	
	def __init__(self, name):
		self.myFixtures = []
		self.name = name
		
	def addFixtureToShow(self, Fixture):
		self.myFixtures.append(Fixture)
		
	def getFixtureByName(self, name):
		i=0
		while self.myFixtures[i].name != name:
			i += 1
		return self.myFixtures[i]
	
	def getDMXFixtureByStartAddress(self, address):
		i=0
		while self.myFixtures[i].DMXStartAddress != address:
			i += 1
		return self.myFixtures[i]
	
#PROPERTY INITIALIZTION	
intensity = NumberProperty("Intensity", 0, 255, 0)

#SETTING INITIALIZATION
singleDMX = Settings("Basic 1 Channel DMX")
singleDMX.addProperty(intensity)

#FIXTURE TYPE INITIALIZATION
fresnel = FixtureType("Fresnel", "DMX", 1, singleDMX)
ellipsoidal = FixtureType("Ellipsoidal", "DMX", 1, singleDMX)
colorBlast12 = FixtureType("ColorBlast12", "DMX", 3, "REPLACE")
dylLight = FixtureType("Dyl-Light", "ACN", 4, "REPLACE")

allMyFixtures = FixtureLibrary()
allMyFixtures.addFixtureToLibrary(fresnel)
allMyFixtures.addFixtureToLibrary(ellipsoidal)